package edu.zut.controller;

import edu.zut.pojo.Employee;
import edu.zut.pojo.Page;
import edu.zut.service.EmpService;
import edu.zut.service.impl.EmpServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "EmpPageServlet", value = "/emp/page")
public class EmpPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取当前是第几页
        String current = request.getParameter("current");
        int currentPage;
        if (null == current){
            currentPage = 1;
        }else {
            currentPage = Integer.parseInt(current);
        }
        Page<Employee> page = new Page<>();
        page.setCurrentPage(currentPage);
        page.setSize(2);
        //查询总记录数以及对应的分页数据
        EmpService empService = new EmpServiceImpl();
        page = empService.queryPage(page);
        request.setAttribute("page",page);
        request.getRequestDispatcher("/view/home.jsp").forward(request,response);



    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
